//
//  ForcumHomeView.m
//  sensen_ios
//
//  Created by justiOS on 16/5/4.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ForcumHomeView.h"

@interface ForcumHomeView ()
@property (nonatomic, strong) UILabel *titleLabel; // 标题
@property (nonatomic, strong) UIImageView *contentImgView; // 内容图片视图

@end

@implementation ForcumHomeView

- (instancetype)initWithFrame:(CGRect)frame {
    if ( self = [super initWithFrame:frame]) {
    }
    
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame mulriple:(CGFloat)mulriple{
    
    if ([super initWithFrame:frame]){
        // 设置自身默认属性
        self.layer.cornerRadius = 4;
        self.backgroundColor = RED_COLOR;
        self.mulriple = mulriple;
        [self _initViews];
    }
    
    return self;
}
#pragma mark -- 创建视图 --
- (void)_initViews {
    
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat width = 0;
    CGFloat height = 0;
    width = MIN(self.width, self.height) * self.mulriple;
    height = width;
    _contentImgView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [_contentImgView setContentMode:UIViewContentModeScaleAspectFit];
    _contentImgView.image = [UIImage imageNamed:@"AQ鱼保姆"];
    [self addSubview:_contentImgView];
    
    y = _contentImgView.bottom ;
    width = 100;
    height = 20;
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _titleLabel.font = B_FONT(14);
    _titleLabel.text = @"未填写标题";
    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_titleLabel];
    
    // 设置标题的位置
    _contentImgView.top = (self.height - _titleLabel.height - _contentImgView.height) / 2.0;
    _contentImgView.center = CGPointMake(self.width / 2.0, _contentImgView.center.y);
    // 设置图片的位置
    _titleLabel.top = _contentImgView.bottom + 5;
    _titleLabel.center = CGPointMake(self.width / 2.0, _titleLabel.center.y);

}
#pragma mark -- 重写set --
- (void)setTitle:(NSString *)title {
    _title = title;
    CGFloat width = [_title getSizeOfBlodString:14].width;
    _titleLabel.width = width;
    _titleLabel.text = _title;
    
    if (SCREEN_WIDTH<=320) {
        _titleLabel.font = [UIFont systemFontOfSize:12];
    }
    
    _titleLabel.center = CGPointMake(self.width / 2.0, _titleLabel.center.y);
}
- (void)setTitleColor:(UIColor *)titleColor{
    _titleColor = titleColor;
    _titleLabel.textColor = titleColor;
}
- (void)setImgName:(NSString *)imgName {
    _imgName = imgName;
    _contentImgView.image = [UIImage imageNamed:_imgName];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
